package Router

import (
	"back_go/Controller"
	"back_go/Controller/Security"
	"time"

	cache "github.com/chenyahui/gin-cache"
	"github.com/chenyahui/gin-cache/persist"
	swaggerFiles "github.com/swaggo/files"

	"github.com/gin-gonic/gin"

	_ "back_go/docs"

	ginSwagger "github.com/swaggo/gin-swagger"
)

func InitRouter(r *gin.Engine) {

	memoryStore := persist.NewMemoryStore(1 * time.Minute)
	r.GET("/test", Controller.Test)

	//静态文件
	r.Static("/upload", "./upload")

	url := ginSwagger.URL("http://localhost:8080/swagger/doc.json") // The url pointing to API definition
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
	//图片上传和获取
	r.POST("/admin/upload", Controller.UploadFileController)
	r.GET("/admin-file/:fileName", cache.CacheByRequestURI(memoryStore, 2*time.Second), Controller.GetAdminFile)
	r.POST("/user/upload/useravatar", Controller.UploadUserImg)
	r.GET("/useravatar/:fileName", cache.CacheByRequestURI(memoryStore, 2*time.Second), Controller.GetUserAvatar)
	r.POST("/user/upload/evaluate", Controller.UploadEvaluate)
	r.GET("/evaluate/:fileName", cache.CacheByRequestURI(memoryStore, 2*time.Second), Controller.GetEvaluate)

	//轮播图上传和获取
	r.POST("/admin/file/upload/element", Controller.UploadIndexImg)
	r.GET("/indexImg/:fileName", cache.CacheByRequestURI(memoryStore, 2*time.Minute), Controller.GetIndexImgFile)

	//用户地址
	userAddrGroup := r.Group("/user")
	{
		userAddrGroup.POST("/addr", Controller.Save)
		userAddrGroup.PUT("/addr", Controller.UpdateById)
		userAddrGroup.GET("/addr/page", Controller.GetUserAddrPage)
		userAddrGroup.GET("/addr/info/:addrId", Controller.GetById)
		userAddrGroup.DELETE("/addr/:addrId", Controller.DeleteById)
	}
	sysUserGroup := r.Group("/sys/user")
	{
		sysUserGroup.POST("", Controller.SaveSysUser)
		sysUserGroup.PUT("", Controller.UpdateSysUser)
		sysUserGroup.DELETE("", Controller.DelSysUser)
		sysUserGroup.POST("/password", Controller.ChangeSysPassword)
		sysUserGroup.GET("/page", Controller.GetSysUserPage)
		sysUserGroup.GET("/info", Controller.GetSysInfoByToken)
		sysUserGroup.GET("/info/:userId", Controller.GetSysInfoById)
	}

	//角色
	sysRoleGroup := r.Group("/sys/role")
	{
		sysRoleGroup.POST("", Controller.SaveRole)
		sysRoleGroup.PUT("", Controller.ChangeRole)
		sysRoleGroup.DELETE("", Controller.DelRoleById)
		sysRoleGroup.GET("/page", Controller.GetRolePage)
		sysRoleGroup.GET("/list", Controller.GetRoleList)
		sysRoleGroup.GET("/info/:roleId", Controller.GetRoleInfoById)
	}

	//菜单
	menuGroup := r.Group("/sys/menu")
	{
		menuGroup.GET("/nav", Controller.GetMenuNav)
		menuGroup.GET("/table", Controller.GetMenuTable)
		menuGroup.GET("/list", Controller.GetMenuList)
		menuGroup.GET("/listRootMenu", Controller.GetMenuListRoot)
		menuGroup.GET("/listChildrenMenu/:menuId", Controller.GetListChildrenMenu)
		menuGroup.GET("/info/:menuId", Controller.GetListInfoByMenuId)
		menuGroup.POST("", Controller.SaveMenu)
		menuGroup.PUT("", Controller.UpdateMenu)
		menuGroup.DELETE("/:menuId", Controller.DelMenuByMenuId)
	}

	//公告
	noticeGroup := r.Group("/shop/notice")
	{
		noticeGroup.GET("/page", Controller.ShopNoticePage)
		noticeGroup.GET("/info/:id", Controller.GetNoticeById)
		noticeGroup.POST("", Controller.SaveNotice)
		noticeGroup.PUT("", Controller.UpdateNotice)
		noticeGroup.DELETE("/:id", Controller.DeleteNoticeById)
	}

	//日志
	r.GET("/sys/log/page", Controller.SysLogPage)

	//地址管理
	r.GET("/admin/area/list", cache.CacheByRequestURI(memoryStore, 2*time.Second), Controller.GetAreaList)
	r.GET("/admin/area/info/:area_id", Controller.GetAreaById)
	r.GET("/admin/area/listByPid", Controller.GetAreaByPid)
	r.POST("/admin/area", Controller.AddArea)
	r.PUT("/admin/area", Controller.UpdateArea)
	r.DELETE("/admin/area/:area_id", Controller.DeleteArea)

	//轮播图管理
	r.GET("/admin/indexImg/page", Controller.GetIndexImg)
	r.GET("/admin/indexImg/info/:imgId", Controller.GetIndexImgById)
	r.POST("/admin/indexImg", Controller.SaveIndexImg)
	r.DELETE("/admin/indexImg", Controller.DetIndexImg)
	r.PUT("/admin/indexImg", Controller.UpdateIndexImg)

	//订单管理
	orderGroup := r.Group("/order/order")
	{
		orderGroup.GET("/page", Controller.GetOrderPage)
		orderGroup.GET("/orderInfo/:orderNumber", Controller.GetOrderByOrderId)
		orderGroup.GET("/soldExcel", Controller.SoldExcel)
		orderGroup.GET("/waitingConsignmentExcel", Controller.WaitingConsignmentExcel)
		orderGroup.PUT("/delivery", Controller.DeliveryOrder) //确认发货
	}

	//快递公司查询
	r.GET("/admin/delivery/list", Controller.DeliveryList)

	//管理员登录
	r.POST("adminLogin", Security.AdminLogin)
	r.POST("/logOut", Security.AdminLogout)

	//运费模板管理
	transportGroup := r.Group("/shop/transport")
	{
		transportGroup.GET("/page", Controller.GetTransportPage) //运费模板分页
		transportGroup.GET("/info/:id", Controller.GetTransportById)
		transportGroup.GET("/list", Controller.GetTransportList) //运费模板列表 在产品管理新建里面用到
		transportGroup.DELETE("", Controller.DeleteTransport)
		transportGroup.POST("", Controller.SaveTransport)
		transportGroup.PUT("", Controller.UpdateTransport) //修改运费模板
	}

	//自提点管理
	pickAddrGrop := r.Group("/shop/pickAddr")
	{
		pickAddrGrop.GET("/page", Controller.GetPickAddrPage)
		pickAddrGrop.GET("/info/:id", Controller.GetPickAddrById)
		pickAddrGrop.DELETE("", Controller.DeletePickAddrById)
		pickAddrGrop.POST("", Controller.SavePickAddr)
		pickAddrGrop.PUT("", Controller.UpdatePickAddr)
	}

	//会员管理
	r.GET("/admin/user/page", Controller.GetUserPage)
	r.GET("/admin/user/info/:userId", Controller.GetUserById)
	r.PUT("/admin/user", Controller.UpdateUser)
	r.DELETE("/admin/user", Controller.DeleteUserById)

	//热搜管理
	r.GET("/admin/hotSearch/page", Controller.GetHotSearchPage)
	r.GET("/admin/hotSearch/info/:id", Controller.GetHotSearchById)
	r.DELETE("/admin/hotSearch", Controller.DeleteHotSearchById)
	r.POST("/admin/hotSearch", Controller.SaveHotSearch)
	r.PUT("/admin/hotSearch", Controller.UpdateHotSearch)

	//分类管理
	prodCateGroup := r.Group("/prod/category")
	{
		prodCateGroup.GET("/table", Controller.GetCategoryTable)
		prodCateGroup.GET("/listCategory", Controller.GetCategoryList)
		prodCateGroup.GET("/info/:categoryId", Controller.GetCategoryById)
		prodCateGroup.GET("/listProdCategory", Controller.GetListProdCategory)
		prodCateGroup.DELETE("/:categoryId", Controller.DeleteCategoryById)
		prodCateGroup.PUT("", Controller.UpdateCategory)
	}

	prodGroup := r.Group("/prod/prod")
	{
		prodGroup.GET("/page", Controller.GetProdByPage)
		prodGroup.GET("/info/:prodId", Controller.GetProdByProdId)
		prodGroup.PUT("", Controller.UpdateProd)
		prodGroup.POST("", Controller.SaveProd)
		prodGroup.DELETE("", Controller.DeleteProd)
	}

	specGroup := r.Group("/prod/spec")
	{
		specGroup.GET("/list", Controller.GetSpecList)
		specGroup.GET("/listSpecMaxValueId", Controller.InfoGetListSpecMaxValueId)
		specGroup.GET("/listSpecValue/:specId", Controller.GetListSpecValue)
		specGroup.GET("/page", Controller.GetProdSpecByPage)
		specGroup.PUT("", Controller.UpdateSpec)
		specGroup.POST("", Controller.SaveSpec)
		specGroup.DELETE("/:id", Controller.DelSpec)
	}

	prodTagGroup := r.Group("/prod/prodTag")
	{
		prodTagGroup.GET("/listTagList", Controller.GetListTagList)
		prodTagGroup.GET("/page", Controller.GetProdTagByPage)
		prodTagGroup.GET("/info/:tagId", Controller.GetProdTagById)
		prodTagGroup.PUT("", Controller.UpdateProdTag)
		prodTagGroup.POST("", Controller.SaveProdTag)
		prodTagGroup.DELETE("/:tagId", Controller.DelProdTag)

	}

	blockInfoGroup := r.Group("/blockInfo")
	{
		blockInfoGroup.GET("/lastBlockInfo", Controller.GetLastBlockInfo)
		blockInfoGroup.GET("/getAllAssetByBlock", Controller.GetAllAssetByBlock)
		blockInfoGroup.GET("/getAssetNumber", Controller.GetAssetNumber)
		blockInfoGroup.GET("/GetAllAssetsWithPage", Controller.GetAllAssetsWithPaginationRemote)
	}
	prodCommGroup := r.Group("/prod/prodComm")
	{
		prodCommGroup.GET("/page", Controller.GetProdCommPage)
		prodCommGroup.GET("/info/:infoId", Controller.GetProdCommById)
		prodCommGroup.POST("", Controller.UpdateProdComm)
		prodCommGroup.PUT("", Controller.UpdateProdComm)
	}
}
